const A = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum: 1,
    tabAct: 0,
    localTypes: [],
    areaType: '',
    area:'',
    business:'',
    businessType: '',
    filterType:[],
    localLives:[]
  },

    // 弹出选择状态和地区
    onFilterbar(e) {
        let type = A.C(e).type;
        if (type == 1) {
            this.setData({
                isFilterType: true,
                isFilterMask: true,
                isFilterArea: false
            })
        } else {
            this.setData({
                isFilterType: false,
                isFilterMask: true,
                isFilterArea: true
            })
        }
    },


    // 选择状态
    onFilterType(e) {
        let value = A.C(e).value;
        let label = A.C(e).label;
        this.setData({
            isFilterType: false,
            isFilterMask: false,
            isFilterArea: false,
            businessType: value,
            business: label,
            localLives:[],
            pageNum:1
        })
        this.getYouthCamps();
    },
    // 选择地区
    onFilterArea(e) {
        let value = A.C(e).value;
        let label = A.C(e).label;
        this.setData({
            isFilterType: false,
            isFilterMask: false,
            isFilterArea: false,
            areaType: value,
            area: label,
            localLives:[],
            pageNum:1
        })
        this.getYouthCamps();
    },

  initLocalTypes() {
    let config = {
      dictType: 'region_type'
    };
    A.updata.getDictDatas(config).then(res => {
      this.setData({
        localTypes: res.list,
        area: res.list[0].dictLabel,
        areaType: res.list[0].dictValue
      })
      this.initBussinessType();
    })
  },

  initBussinessType(){
      let config = {
          dictType: 'youth_org_type'
      }
      A.updata.getdictData(config).then(res => {
          this.setData({
              filterType: res.list,
              business: res.list[0].dictLabel,
              businessType: res.list[0].dictValue
          });
          this.getYouthCamps()
      })
  },

  getYouthCamps(){
    let config = {
      areaType: this.data.areaType,
      businessType:this.data.businessType,
      name: '',
      pageNum: this.data.pageNum++,
      pageSize: 10
    };
    A.updata.getYouthCamps(config).then(res => {
      let localLives = this.data.localLives;
      this.setData({
        localLives: localLives.concat(res.list)
      })
    })
  },

  // 跳转商家详情
  toShopInfo(e) {
    let goodId = A.C(e).id;
    wx.navigateTo({
      url: `/pages/index/youth/detail/detail?id=${goodId}`
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initLocalTypes();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getYouthCamps();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})